﻿
#region Imports...
using System;
using System.Web.UI.WebControls;
using Pharmacy.Data;
using Pharmacy.Entities;
using Pharmacy.Web.UI;
#endregion

public partial class DrugDispoEdit : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{		
		FormUtil.RedirectAfterInsertUpdate(FormView1, "DrugDispoEdit.aspx?{0}", DrugDispoDataSource);
		FormUtil.RedirectAfterAddNew(FormView1, "DrugDispoEdit.aspx");
		FormUtil.RedirectAfterCancel(FormView1, "DrugDispo.aspx");
		FormUtil.SetDefaultMode(FormView1, "DrugId");
        var httpCookie = Request.Cookies["LoginUser"];
        if (httpCookie != null)
        {
            WebUser id = DataRepository.WebUserProvider.GetByUserId(httpCookie.Value);
            if (id.Roles != "Pharmacist")
            {
                if (FormView1.CurrentMode == FormViewMode.Edit)
                {
                    FormView1.FooterRow.FindControl("UpdateButton").Visible = true;
                }
                else
                {
                    FormView1.FooterRow.FindControl("InsertButton").Visible = true;
                }
            }
        }
	}
	protected void GridViewGrnDetails1_SelectedIndexChanged(object sender, EventArgs e)
	{
		string urlParams = string.Format("GrnDetailId={0}", GridViewGrnDetails1.SelectedDataKey.Values[0]);
		Response.Redirect("GrnDetailsEdit.aspx?" + urlParams, true);		
	}	
	protected void GridViewStock2_SelectedIndexChanged(object sender, EventArgs e)
	{
		string urlParams = string.Format("DrugId={0}&ExpDate={1}&BatchLot={2}", GridViewStock2.SelectedDataKey.Values[0], GridViewStock2.SelectedDataKey.Values[1], GridViewStock2.SelectedDataKey.Values[2]);
		Response.Redirect("StockEdit.aspx?" + urlParams, true);		
	}	
	protected void GridViewDrugDiscount3_SelectedIndexChanged(object sender, EventArgs e)
	{
		string urlParams = string.Format("MemberType={0}&DrugId={1}", GridViewDrugDiscount3.SelectedDataKey.Values[0], GridViewDrugDiscount3.SelectedDataKey.Values[1]);
		Response.Redirect("DrugDiscountEdit.aspx?" + urlParams, true);		
	}	
	protected void GridViewPrescriptionDetail4_SelectedIndexChanged(object sender, EventArgs e)
	{
		string urlParams = string.Format("PrescriptionDetailId={0}", GridViewPrescriptionDetail4.SelectedDataKey.Values[0]);
		Response.Redirect("PrescriptionDetailEdit.aspx?" + urlParams, true);		
	}
    protected void GridViewStockOutDetails1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string urlParams = string.Format("StockOutDetailId={0}", GridViewStockOutDetails1.SelectedDataKey.Values[0]);
        Response.Redirect("StockOutDetailsEdit.aspx?" + urlParams, true);
    }
}


